package com.lanren.familybookapp.ui.home.presenter;

import com.lanren.common.base.impl.BasePresenter;
import com.lanren.familybookapp.ui.home.bean.BookListBean;
import com.lanren.familybookapp.ui.home.interfaces.IHomeModel;
import com.lanren.familybookapp.ui.home.model.HomeModel;
import com.lanren.familybookapp.ui.me.bean.BookInfoBean;

import java.util.List;

/**
 * @ClassName HomePresenter
 * @Description TODO
 * @Author chongheng.wang
 * @Date 2019/10/5 16:58
 * @Version 1.0
 */
public class HomePresenter extends BasePresenter<IHomeModel.IHomeView> {
    private HomeModel homeModel;

    public HomePresenter(HomeModel homeModel) {
        this.homeModel = homeModel;
    }

    public void getBookList(int bookId, String bookTime, int page, String member) {

        homeModel.getBookList(bookId, bookTime, page, member, new IHomeModel.HomeModel() {
            @Override
            public void onError(int code, String msg) {
                mRootView.showError(code, msg);
            }

            @Override
            public void onSuccess(List<BookListBean> bookListBeans) {
                mRootView.onSuccess(bookListBeans);
            }

        });
    }

    public void getBookInfo(int bookId) {
        homeModel.getBookInfo(bookId, new IHomeModel.GetBookInfoModel() {
            @Override
            public void onError(int code, String msg) {
                mRootView.showError(code, msg);
            }

            @Override
            public void onSuccess(List<BookInfoBean> bookInfoBeans) {
                mRootView.onGetBookInfoSuccess(bookInfoBeans);
            }
        });
    }

    public void getUserInfo() {
        homeModel.getUserInfo(new IHomeModel.MainUserInfoModel() {
            @Override
            public void onError(int code, String data) {
                mRootView.showError(code, data);
            }

            @Override
            public void onSuccess() {
                mRootView.onSuccess();
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (homeModel != null) {
            homeModel.clearDisposable();
            homeModel = null;
        }
    }
}
